package field_method07;
import java.util.ArrayList;
import java.util.Scanner;
public class KTV {
    private static ArrayList<String> songList = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("----欢迎来到点歌系统------------");
        System.out.println("1.添加歌曲至列表");
        System.out.println("2.将歌曲置顶");
        System.out.println("3.将歌曲前移一位");
        System.out.println("4.退出");
        System.out.println("5.查看歌曲列表");
        System.out.println("6.删除歌曲信息");

        while (true) {
            System.out.print("请输入指令：");
            int choice = scanner.nextInt();
            scanner.nextLine(); // 清除输入流中的换行符

            switch (choice) {
                case 1:
                    addSong();
                    break;
                case 2:
                    topSong();
                    break;
                case 3:
                    moveUpSong();
                    break;
                case 4:
                    System.out.println("退出系统，再见！");
                    System.exit(0);
                case 5:
                    showSongs();
                    break;
                case 6:
                    deleteSong();
                    break;
                default:
                    System.out.println("无效指令，请重新输入！");
            }
        }
    }

    private static void addSong() {
        System.out.print("请输入歌曲名：");
        String songName = scanner.nextLine();
        songList.add(songName);
        System.out.println("歌曲添加成功，当前歌曲列表：" + songList);
    }

    private static void topSong() {
        System.out.print("请输入要置顶的歌曲名：");
        String songName = scanner.nextLine();
        if (songList.remove(songName)) {
            songList.add(0, songName);
            System.out.println("歌曲置顶成功，当前歌曲列表：" + songList);
        } else {
            System.out.println("歌曲名不存在，无法置顶！");
        }
    }

    private static void moveUpSong() {
        System.out.print("请输入要前移的歌曲名：");
        String songName = scanner.nextLine();
        int index = songList.indexOf(songName);
        if (index > 0) {
            songList.remove(index);
            songList.add(index - 1, songName);
            System.out.println("歌曲前移成功，当前歌曲列表：" + songList);
        } else {
            System.out.println("歌曲名不存在或已经是第一个，无法前移！");
        }
    }

    private static void showSongs() {
        System.out.println("当前歌曲列表：" + songList);
    }

    private static void deleteSong() {
        System.out.print("请输入要删除的歌曲名：");
        String songName = scanner.nextLine();
        if (songList.remove(songName)) {
            System.out.println("歌曲删除成功，当前歌曲列表：" + songList);
        } else {
            System.out.println("歌曲名不存在，无法删除！");
        }
    }
}